package co.yixiang.modules.shop.web.controller;

import co.yixiang.modules.order.web.param.InvestOrderParam;
import co.yixiang.modules.shop.entity.YxInvestCustomer;
import co.yixiang.modules.shop.entity.YxStoreQuestionnaire;
import co.yixiang.modules.shop.service.YxInvestCustomerService;
import co.yixiang.modules.shop.service.YxStoreQuestionnaireService;
import co.yixiang.modules.shop.web.param.YxStoreQuestionnaireQueryParam;
import co.yixiang.modules.shop.web.vo.YxInvestCustomerQueryVo;
import co.yixiang.modules.shop.web.vo.YxStoreQuestionnaireQueryVo;
import co.yixiang.common.web.controller.BaseController;
import co.yixiang.common.api.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

import co.yixiang.common.web.vo.Paging;
import co.yixiang.common.web.param.IdParam;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 调查问卷表 前端控制器
 * </p>
 *
 * @author hisen
 * @since 2020-06-15
 */
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "调查问卷模块", tags = "投资端:调查问卷模块", description = "调查问卷模块")
public class YxStoreQuestionnaireController extends BaseController {

    @Autowired
    private YxStoreQuestionnaireService yxStoreQuestionnaireService;
    @Autowired
    private YxInvestCustomerService yxInvestCustomerService;



    /**
     * 投资客户表分页列表
     */
    @PostMapping("/questionnaire/list")
    @ApiOperation(value = "题目列表",notes = "题目列表")
    public ApiResult<List<YxStoreQuestionnaire>> questionnaireList(@RequestBody YxInvestCustomerQueryVo yxInvestCustomer) throws Exception{
        //保存客户信息
        YxInvestCustomer customer = yxInvestCustomerService.getByPhone(yxInvestCustomer.getInvestPhone());
        if(customer == null && !yxInvestCustomer.getInvestPhone().equals("")){
            YxInvestCustomer customerNew = new YxInvestCustomer();
            customerNew.setInvestPhone(yxInvestCustomer.getInvestPhone());
            customerNew.setInvestName(yxInvestCustomer.getInvestName());
            customerNew.setSalesManName(yxInvestCustomer.getSalesManName());
            customerNew.setInvestIdcard(yxInvestCustomer.getInvestIdcard());
            customerNew.setSalesManId(yxInvestCustomer.getSalesManId());
            customerNew.setAddTime(new Date());
            customerNew.setType(2);
            yxInvestCustomerService.save(customerNew);
        }
        return ApiResult.ok(yxStoreQuestionnaireService.questionnaireList());
    }

    /**
     * 保存答题结果
     */
    @PostMapping("/questionnaire/answer")
    @ApiOperation(value = "保存答题结果",notes = "保存答题结果")
    public ApiResult<Object> answer() throws Exception{
        return ApiResult.ok((int)(Math.random()*31 + 70));
    }



}

